<?php Schema::init(); ?>
<div class="schema_wrapper">
	<?php if ($error != -1) { ?>
		<div class="schema_message">
		<?php if (!$error) {
			echo 'File updated sucsesfuly';
		} else if ($error == -2) {
			echo 'File inserted sucsesfuly';
		} else {
			echo 'Error updating File';
		} ?>
		</div>
	<?php } ?>

	<div class="schema_header">
		Updating file
	</div>
	<form action="<?php echo CURRENT_URL, $info['id']; ?>" method="post">
		<div class="schema_tabs">
			<a href="#0" id="schema_tab_0" class="tab_on" onclick="Core.Schema.openTab(0)">General</a>
		</div>
		<div class="schema_blocks">
			<div class="schema_block" id="schema_block_0">
				<table border="0" width="100%" cellspacing="10" cellpadding="0">
					<colgroup>
						<col class="schema_column_headers" />
						<col class="schema_column_fields" />
					</colgroup>
					<tr>
						<td class="schema_cell_header">File</td>
						<td class="schema_cell_field">
							<?php
							$max_length = 100;
							$style = '';
							if (in_array($info['extension'], Config::get('file_images_extensions'))) {
								if (!is_null($info['name_thumb'])) {
									$preview = UPLOAD_URL . $info['name_thumb'];
								} else {
									$preview = UPLOAD_URL . $info['name'];
								}

								if ((intval($info['width']) > $max_length) || (intval($info['height']) > $max_length)) {
									if (intval($info['width']) >= intval($info['height'])) {
										$style .= 'width:' . $max_length . 'px;';
									} else {
										$style .= 'height:' . $max_length . 'px;';
									}
								}
							} else {
								$file_icon = File::getIcon($info['extension']);
								$preview = PUBLIC_URL . 'images/file/' . $file_icon;
								$style = 'width:48px; height:48px;';
							}
							$popup = $info['name_orig']; ?>
							<a href="<?php echo UPLOAD_URL, $info['name']; ?>" target="_blank"><img src="<?php echo $preview; ?>" style="display:block; border:none; <?php echo $style; ?>" alt="File" /></a>
						</td>
					</tr>
					<tr>
						<td class="schema_cell_header">Original name</td>
						<td class="schema_cell_field"><?php echo $info['name_orig']; ?></td>
					</tr>
					<tr>
						<td class="schema_cell_header">File size</td>
						<td class="schema_cell_field"><?php echo File::formatSize($info['size']); ?></td>
					</tr>
				<?php if ((intval($info['width']) > 0) && (intval($info['height']) > 0)) {?>
					<tr>
						<td class="schema_cell_header">Dimension</td>
						<td class="schema_cell_field"><?php echo $info['width'], ' x ', $info['height']; ?></td>
					</tr>
				<?php } ?>
					<tr>
						<td class="schema_cell_header">Delete file</td>
						<td class="schema_cell_field"><a href="<?php echo BASE_URL; ?>file/delete/<?php echo $info['id'] ,'/', $cat_id; ?>">Delete</a></td>
					</tr>
					<tr>
						<td class="schema_cell_header">Status</td>
						<td class="schema_cell_field">
							<select id="doc_status_id" name="doc_status_id" class="schema_select">
								<option value="1"<?php if (1 == intval($info['status_id'])) { ?> selected="selected"<?php } ?>>Opened</option>
								<option value="2"<?php if (2 == intval($info['status_id'])) { ?> selected="selected"<?php } ?>>Closed</option>
							</select>
						</td>
					</tr>
					<tr>
						<td class="schema_cell_header">Parent category</td>
						<td class="schema_cell_field">
							<select id="file_cat_id" name="file_cat_id" class="schema_select">
								<?php Category::drawTreeSelect(2, $cat_id); ?>
							</select>
						</td>
					</tr>
					<tr>
						<td class="schema_cell_header">Link to file</td>
						<td class="schema_cell_field"><input type="text" value="<?php echo UPLOAD_URL, $info['name']; ?>" class="schema_textfield" onclick="$(this).select()" readonly="true" /></td>
					</tr>
				<?php if (intval($info['insert_user_id']) > 0) { ?>
					<tr>
						<td class="schema_cell_header">Inserted by</td>
						<td class="schema_cell_field"><?php echo User::getName($info['insert_user_id']); ?></td>
					</tr>
				<?php } ?>

				<?php if (intval($info['insert_time']) > 0) { ?>
					<tr>
						<td class="schema_cell_header">Inserted at</td>
						<td class="schema_cell_field"><?php echo User::getDate(User::getId(), $info['insert_time']); ?></td>
					</tr>
				<?php } ?>

				<?php if (intval($info['update_user_id']) > 0) { ?>
					<tr>
						<td class="schema_cell_header">Updated by</td>
						<td class="schema_cell_field"><?php echo User::getName($info['update_user_id']); ?></td>
					</tr>
				<?php } ?>

				<?php if (intval($info['update_time']) > 0) { ?>
					<tr>
						<td class="schema_cell_header">Updated at</td>
						<td class="schema_cell_field"><?php echo User::getDate(User::getId(), $info['update_time']); ?></td>
					</tr>
				<?php } ?>

				<?php if (intval($info['delete_user_id']) > 0) { ?>
					<tr>
						<td class="schema_cell_header">Deleted by</td>
						<td class="schema_cell_field"><?php echo User::getName($info['delete_user_id']); ?></td>
					</tr>
				<?php } ?>

				<?php if (intval($info['delete_time']) > 0) { ?>
					<tr>
						<td class="schema_cell_header">Deleted at</td>
						<td class="schema_cell_field"><?php echo User::getDate(User::getId(), $info['delete_time']); ?></td>
					</tr>
				<?php } ?>
				</table>
			</div>
		</div>
		<div class="schema_buttons"><input type="submit" value="Update" class="schema_submit" /></div>
	</form>
</div>